package org.me.SendSMS;

import java.util.ArrayList;
import java.util.List;

import org.me.SendSMS.adapter.MessageTypeAdapter;
import org.me.SendSMS.data.MessageType;
import org.me.SendSMS.utli.GlobalVariable;
import org.me.SendSMS.utli.XMLUtli;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;

public class MessageTypeActivity extends Activity {
	
	ListView mListView;
	Button btngoBack;
	Button btnRandom;
	private Bundle extra;
	Context mContext;
	LinearLayout llAdMode1;
	private MessageTypeAdapter adapter;
	List<MessageType> mMessageType = new ArrayList<MessageType>();
	private GoogleAnalyticsTracker tracker;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 tracker = GoogleAnalyticsTracker.getInstance();
	     // Start the tracker in manual dispatch mode...
	    tracker.startNewSession("UA-35081259-1", getApplication());
		setContentView(R.layout.listview_message_type);
		mContext		= this;
		extra 			= getIntent().getExtras();
		String file 	= extra.getString("file");
		Log.e("oncreate", "file = "+file);
		btngoBack		= (Button) findViewById(R.id.btnBack);
		btnRandom		= (Button) findViewById(R.id.btnRandom);
		llAdMode1		= (LinearLayout) findViewById(R.id.llAdmob1);
		btngoBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		llAdMode1 = (LinearLayout)findViewById(R.id.llAdmob1);
		

		try {
			AdView adView = new AdView(this, AdSize.BANNER, "a1503c30e415e29");
			  
		    // Add the adView to it
			llAdMode1.addView(adView);
		     
		    // Initiate a generic request to load it with an ad
		    AdRequest request = new AdRequest();
		    request.setTesting(true);

		    adView.loadAd(request);  
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		btnRandom.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String str = "";
				for(int i = 0; i< mMessageType.size(); i++)
				{
					str += mMessageType.get(i).GetTitle() + "/";
				}
					Log.w("MessageTypeActivity", "str = "+str);
					GlobalVariable.RANDOM 		= true;
					GlobalVariable.HIDDEN 		= true;
					Intent myIntent 			= new Intent(mContext, SendSMSActivity.class);
					myIntent.putExtra("string", str);
					myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					mContext.startActivity(myIntent);
			}
		});
		mListView					= (ListView) findViewById(R.id.listMessageType);
		mMessageType 				= XMLUtli.parserXMLMessageType(mContext, file) ;
		GlobalVariable.mMessageType = mMessageType; 
		
		adapter = new MessageTypeAdapter(mContext, mMessageType);
		
		mListView.setAdapter(adapter);
		
	}

}
